Perl Examples by Ray Yao

Perl Examples by Ray Yao

Author:Ray Yao [Yao, Ray]
Language: eng
Format: azw3, epub, mobi
Published: 2021-06-30T00:00:00+00:00


Output:

$x = 0 , $y = 1

$x & $y = 0

$x | $y = 1

$x ^ $y = 1

14. Pass Hash Parameters

Example:

# define a method

sub func{

my (%hash) = @_;

foreach my $key ( keys %hash ){

my $value = $hash{$key};

print "$key : $value
";

}

}

%hash = ('title' => 'Java', 'hours' => 8);

# pass a hash parameter

func(%hash);

Output:

title : Java

hours : 8

15. Global & Local

Example:

# global variable

$str = "Hi, anybody!";

# define a function

sub func{

my $str; # my define a private variable

$str = "Hi, my friend!";

print "A string inside the function:$str
";

}

# call the function

func();

print "A string outside the function:$str
";



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.